class OwnedUsersController < ApplicationController
  layout "main"
  active_scaffold :auto_user do |config|
    config.label = '<br/>'
    config.list.per_page = 10
    config.actions = [:show, :list, :update]
    config.columns = [:id, :login, :gender, :title, :fname, :lname, :nid, :dob, :education, :org, :position, :sport, :user_type, :email, :address, :zip, :province, :phone, :cellphone, :image, :show_image, :role]
    config.columns[:province].form_ui = :select
    config.columns[:province].options = {:options => Province.find(:all, :order => "th" ).map {|p| [p.th, p.th] }}
    config.columns[:title].form_ui = :select
    config.columns[:title].options = {:options => UserTitle.find(:all, :order => "name" ).map {|ut| [ut.name, ut.name] }}
    config.columns[:gender].form_ui = :select
    config.columns[:gender].options = {:options => %w[ชาย หญิง]}
    config.columns[:education].form_ui = :select
    config.columns[:education].options = {:options => Education.find(:all, :order => "name" ).map {|e| [e.name, e.id] }}
    config.columns[:user_type].form_ui = :select
    config.columns[:user_type].options = {:options => UserType.find(:all, :order => "name" ).map {|ut| [ut.name, ut.id] }}
    config.columns[:gender].label = "เพศ"
    config.columns[:title].label = "คำนำหน้าชื่อ"
    config.columns[:fname].label = "ชื่อ"
    config.columns[:lname].label = "นามสกุล"
    config.columns[:nid].label = "เลขประจำตัวประชาชน"
    config.columns[:dob].label = "วันเกิด(yyyy-mm-dd)"
    config.columns[:education].label = "การศึกษา"
    config.columns[:org].label = "หน่วยงาน/บริษัท"
    config.columns[:position].label = "ตำแหน่ง/อาชีพ"
    config.columns[:user_type].label = "ประเภทผู้ใช้งาน"
    config.columns[:address].label = "ที่อยู่"
    config.columns[:province].label = "จังหวัด"
    config.columns[:zip].label = "รหัสไปรษณีย์"
    config.columns[:sport].label = "กีฬา"
    config.columns[:role].label = "ระดับสิทธิ์"
    config.update.columns.exclude :id, :login, :show_image
    config.list.columns.exclude :nid, :dob, :education, :org, :position, :sport, :user_type, :email, :address, :province, :zip, :phone, :cellphone, :image, :show_image
    config.list.sorting = {:id => 'ASC'}
  end

  protected

  def conditions_for_collection
    ['id=?', session[:user_id]]
  end
end
